<?php
// +----------------------------------------------------------------------
// | EasyAdmin
// +----------------------------------------------------------------------
// | PHP交流群: 763822524
// +----------------------------------------------------------------------
// | 开源协议  https://mit-license.org 
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zhongshaofa/EasyAdmin
// +----------------------------------------------------------------------
namespace app\model\api;

use laytp\BaseModel;
class PotterQuestion extends BaseModel
{
    protected $limit = 20;

    /**
     * 获取问题列表
     * @param $type
     * @param $keyword
     * @param $guide
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function list($type,$keyword,$guide){
        $where = [];
        if($type){
            $where[] = ['type', '=', $type];
        }
        if($keyword){
            $where[] = ['question', 'like', '%'.$keyword.'%'];
        }
        if($guide){
            $where[] = ['guide', '=', $guide];
        }
        $list = $this->where($where)
            ->order('id asc')
            ->cache(true)
            ->paginate($this->limit)
            ->toArray();

        return $list;
    }

    /**
     * 字母导航列表
     * @param $type
     * @return array
     */
    public function getTagList($type){
        $list = $this
            ->where('type','=',$type)
            ->cache(true)
            ->column('guide');
        $list = array_values(array_filter(array_unique($list)));
        return $list;
    }

}